/**
 * 
 */
package com.wubo.sec.log;

import java.util.List;

import org.springframework.context.ApplicationListener;

import com.wubo.sec.event.LogEvent;

/** 日志事件监听器，当捕获到日志事件后，调用已注册的日志记录器
 * @author wubo
 * @CreateDate 2010-7-29
 * @version 1.0.01
 */
public class LogAppenderRegistry implements ApplicationListener<LogEvent>{

	private List<ILogAppender> logAppenders;

	public LogAppenderRegistry() {
		super();
	}
	
	public void setLogAppenders(List<ILogAppender> logAppenders) {
		this.logAppenders = logAppenders;
	}

	public List<ILogAppender> getLogAppenders() {
		return logAppenders;
	}
	
	public void onApplicationEvent(LogEvent event) {
		// TODO Auto-generated method stub
		ILog log = (ILog) event.getSource();
		if(logAppenders != null){
			for(int i=0; i<logAppenders.size(); i++){
				ILogAppender appender = logAppenders.get(i);
				if( appender.supports(log.getClass()) ){
					appender.append(log);
				}
			}
		}
	}
	
}
